#include <bits/stdc++.h>

using namespace std;

#define int long long

void solve()
{
    int n; cin >> n;
    vector<int>v(n);
    vector<int> distinct(n), frep(n + 1);

    int total = 0;
    for(int i = 0;i < n;i ++)
    {
        cin >> v[i];
        frep[v[i]]++;
        if(frep[v[i]] == 1) distinct[i] = 1;
        distinct[i] += (i ? distinct[i - 1] : 0);
    }
    fill(frep.begin() , frep.end() , 0);
    int ans = 0, end = n - 1;
    total = 0;
    for(int i = n - 1;i >= 0;i--)
    {
        frep[v[i]]++;
        if(frep[v[i]] == 1) total++;

        if(total == distinct[end])
        {
            ans++;
            for(int j = i;j <= end;j ++) frep[v[j]] = 0;
            end = i - 1;
            total = 0;
        }
    }
    //[5, 8, 7, 5, 8, ..5, 7, 8, 10, 9]
    //distinct = [1, 2, 3, 3, 3, 3, 3, 3, 4, 5]
    cout << ans << endl;
}
signed main()
{
    int t; cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}